package cn.hnc.checkapi.repository;

import java.util.List;

import cn.hnc.checkapi.bean.Motor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface MotorRepository extends JpaRepository<Motor, Long> {
   List findByProductId(Long productId);

   @Query(
      value = "select elecModel, elecName as name, max(cur) as max, min(cur) as min, avg(cur) as average from motor where 1 = 1 and if(isnull(?1) || length(trim(?1)) < 1, 1 = 0, elecModel = ?1) group by elecName, elecModel",
      nativeQuery = true
   )
   List findAtrributeByElecModel(String elecModel);

   void deleteByProductId(Long productId);
}
